{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加商品</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="userAdd" id="add_article" enctype="multipart/form-data">
                        <input type="hidden" name="id" value="{$res['good_id']}">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">商品名称</label>
                            <div class="input-group col-sm-4">
                                <input id="good_name" type="text" class="form-control" name="good_name" value="{$res['good_name']?$res['good_name']:''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用户价格</label>
                            <div class="input-group col-sm-4">
                                <input id="good_price" type="number" min="1" class="form-control" name="good_price" value="{$res['good_price']?$res['good_price']:''}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">运行端价格</label>
                            <div class="input-group col-sm-4">
                                <input id="y_price" type="number" min="1" class="form-control" name="y_price" value="{$res['y_price']?$res['y_price']:''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">货号</label>
                            <div class="input-group col-sm-4">
                                <input id="good_huohao" type="text" class="form-control" name="good_huohao" value="{$res['good_huohao']?$res['good_huohao']:''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">规格</label>
                            <div class="input-group col-sm-4">
                                <input id="good_guige" type="text" class="form-control" name="good_guige" value="{$res['good_guige']?$res['good_guige']:''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">长</label>
                            <div class="input-group col-sm-4">
                                <input id="good_chang" type="text" class="form-control" name="good_chang" value="{$res['good_chang']?$res['good_chang']:''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">宽</label>
                            <div class="input-group col-sm-4">
                                <input id="good_kuan" type="text" class="form-control" name="good_kuan" value="{$res['good_kuan']?$res['good_kuan']:''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">高</label>
                            <div class="input-group col-sm-4">
                                <input id="good_gao" type="text" class="form-control" name="good_gao" value="{$res['good_gao']?$res['good_gao']:''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">毛重</label>
                            <div class="input-group col-sm-4">
                                <input id="good_mao" type="text" class="form-control" name="good_mao" value="{$res['good_mao']?$res['good_mao']:''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">净重</label>
                            <div class="input-group col-sm-4">
                                <input id="good_jing" type="text" class="form-control" name="good_jing" value="{$res['good_jing']?$res['good_jing']:''}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">上市年份</label>
                            <div class="input-group col-sm-4">
                                <input type="text"  name="start" onfocus="wk.lay_date(this);" value="{$res['good_ss_time']?$res['good_ss_time']:''}" class="layui-input layer-date search" placeholder="上市年份" />
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">缩略图</label>
                            <div class="input-group col-sm-5">
                                <input type="hidden" id="data_photo" name="images" >
                                <div id="imgPicker" style="float:left">选择图片</div>
                                <img id="img_data" height="100px" style="float:left;margin-left: 50px;margin-top: -10px;cursor:pointer;" src="{$res.good_thumb}" onclick='imgDisplay(this)'/>
                                <div id="fileList" class="uploader-list" style="float:right"></div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label yanse">品牌：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="good_pinpai">
                                    {if !empty($pinpai)}
                                    {foreach name="pinpai" item="vo"}
                                    <option value="{$vo.p_id}" {if $vo['p_id']==$res['good_pinpai']} selected {/if}>{$vo.p_name}</option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label yanse">型号：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="good_xinghao">
                                    {if !empty($xinghao)}
                                    {foreach name="xinghao" item="vo"}
                                    <option value="{$vo.x_id}" {if $vo['x_id']==$res['good_xinghao']} selected {/if}>{$vo.x_name}</option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label yanse">是否是热门：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="good_hot">
                                    <option value="1" {if $res['good_hot']==1} selected {/if}>普通</option>
                                    <option value="2" {if $res['good_hot']==2} selected {/if}>热门</option>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label yanse">商品轮播图：</label>
                            <div class="input-group col-sm-7">
                                <div class="page-container">
                                    <input type="hidden" name="del" id="del" value="">
                                    <input type="hidden" id="hid" value="{$res.good_image}">
                                    <input type="hidden" name="photo" id="photo" value="{$res.good_image}">
                                    <div id="uploader" class="wu-example">
                                        <div class="queueList">
                                            <div id="dndArea" class="placeholder">
                                                <div id="filePicker"></div>
                                                <p>或将照片拖到这里,支持JPG,JPEG,PNG,BMP,GIF</p >
                                            </div>
                                        </div>
                                        <div class="statusBar" style="display:none;">
                                            <div class="progress progress-striped active">
                                                <div class="progress-bar progress-bar-success">
                                                    <span>0%</span>
                                                </div>
                                            </div>
                                            <div class="info"></div>
                                            <div class="btns">
                                                <div id="filePicker2"></div>
                                                <div class="uploadBtn">开始上传</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!--<span class="help-block m-b-none photos" ><i class="fa fa-info-circle"></i> 必填</span>-->
                                <a id="myPhoto"  class="photos" style="color:#A94543"></a>
                            </div>
                        </div>
                        <div class="form-group" id="MyContent">
                            <label class="col-sm-3 control-label cyanse" for="myEditor">商品富文本：</label>
                            <div class="input-group col-sm-9">
                                <textarea   class="good_content" name="good_content" style="width:90%" id="myEditor"><?php echo(html_entity_decode($res['good_content']?$res['good_content']:''))?></textarea>
                                <a id="myEditors" style="color:#A94543"></a>
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-3 control-label cyanse" for="Editor">商品参数富文本：</label>
                            <div class="input-group col-sm-9">
                                <textarea  class="good_canshu" name="good_canshu" style="width:90%" id="Editor"><?php echo(html_entity_decode($res['good_canshu']?$res['good_canshu']:''))?></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary btsave" type="button"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="__JS__/webupload/webuploader_update1.js"></script>
<script type="text/javascript" src="__JS__/Crop.js"></script>
<script src="__JS__/plugins/ueditor/ueditor.config.js" ></script>
<script src="__JS__/plugins/ueditor/ueditor.all.js" ></script>
<script type="text/javascript">

    //图片灯箱
    function imgDisplay(obj) {
        var src = $(obj).attr("src");
        var imgHtml = '<div class="showP"><img src=' + src + ' style="margin-top: 30px;height:90%;margin-bottom: 50px;"  /><p class="closeP"  onclick="closePicture(this)"><span class="cha">×</span></p></div>'
        $('body').append(imgHtml);
    }

    //关闭图片灯箱
    function closePicture(obj) {
        $(obj).parent("div").remove();
    }

    //百度富文本编辑器
    var editor = UE.getEditor('myEditor', {
        initialFrameHeight:450,
        autoHeight: false,
        autoHeightEnabled:false,
        autoFloatEnabled:false,
        catchRemoteImageEnable:false

    });
    var editor1 = UE.getEditor('Editor', {
        initialFrameHeight:450,
        autoHeight: false,
        autoHeightEnabled:false,
        autoFloatEnabled:false,
        catchRemoteImageEnable:false
    });
    //上传图片到第三方CDN
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage') {
            return '/admin/Upload/ueditorUpload';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }
</script>
<script type="text/javascript">
    wk.upload("{:url('Upload/upload')}",2);

    //裁剪后的处理
    $("#sureCut").on("click",function () {
        if ($("#tailoringImg").attr("src") == null ){
            return false;
        }else{
            var cas = $('#tailoringImg').cropper('getCroppedCanvas');//获取被裁剪后的canvas
            var base64url = cas.toDataURL('image/png'); //转换为base64地址形式
            $("#img_data").attr('src',base64url).show();
            $('#data_photo').val(base64url);
            //关闭裁剪框
            $("#myModal").modal('hide');
        }
    });
    $(".btsave").on('click',function () {
        $('.btn').attr('disabled',true);
        var  good_name = $("input[name='good_name']").val();
        var  good_price = $("input[name='good_price']").val();
        var  y_price = $("input[name='y_price']").val();
        var  good_huohao = $("input[name='good_huohao']").val();
        if(good_name==''){
            layer.msg("商品名称不能为空", {icon: 1, time: 1500, shade: 0.1}, function (index) {
            });
            $('.btn').removeAttr('disabled');
            return false;
        }
        if(good_price==''){
            layer.msg("用户端价格不能为空", {icon: 1, time: 1500, shade: 0.1}, function (index) {
            });
            $('.btn').removeAttr('disabled');
            return false;
        }
        if(y_price==''){
            layer.msg("运行端价格不能为空", {icon: 1, time: 1500, shade: 0.1}, function (index) {
            });
            $('.btn').removeAttr('disabled');
            return false;
        }
        if(good_price <= 0 || y_price <= 0){
            layer.msg("商品价格不能低于0", {icon: 1, time: 1500, shade: 0.1}, function (index) {
            });
            $('.btn').removeAttr('disabled');
            return false;
        }
        if(good_huohao==''){
            layer.msg("货号不能为空", {icon: 1, time: 1500, shade: 0.1}, function (index) {
            });
            $('.btn').removeAttr('disabled');
            return false;
        }
        $.ajax({
            url: "{:url('update')}",
            type: "post",
            dataType:'json',
            data: $("#add_article").serialize(),
            success: function (data) {
                if (data.code == 200) {
                    wk.success(data.msg,"{:url('shop/index')}",1);
                } else if(data.code == 100){
                    $('.btn').removeAttr('disabled');
                    wk.error(data.msg,'',2);
                    return false;
                }
            }
        });
    })

</script>
</body>
</html>